{% extends "pretixcontrol/event/base.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% load urlreplace %}
{% block title %}{% trans "Dates" context "subevent" %}{% endblock %}
{% block content %}
    <h1>{% trans "Dates" context "subevent" %}</h1>
    {% if subevents|length == 0 and not filter_form.filtered %}
        <div class="empty-collection">
            <p>
                {% blocktrans trimmed %}
                    You haven't created any dates for this event series yet.
                {% endblocktrans %}
            </p>

            <a href="{% url "control:event.subevents.add" organizer=request.event.organizer.slug event=request.event.slug %}"
                    class="btn btn-primary btn-lg"><i class="fa fa-plus"></i>
                {% trans "Create a new date" context "subevent" %}</a>
            <a href="{% url "control:event.subevents.bulk" organizer=request.event.organizer.slug event=request.event.slug %}"
                    class="btn btn-primary btn-lg"><i class="fa fa-plus"></i>
                {% trans "Create many new dates" context "subevent" %}</a>
        </div>
    {% else %}
        <form class="row filter-form" action="" method="get">
            <div class="col-md-2 col-sm-6 col-xs-12">
                {% bootstrap_field filter_form.query layout='inline' %}
            </div>
            <div class="col-md-2 col-sm-6 col-xs-12">
                {% bootstrap_field filter_form.status layout='inline' %}
            </div>
            <div class="col-md-2 col-sm-6 col-xs-12">
                {% bootstrap_field filter_form.date_from layout='inline' %}
            </div>
            <div class="col-md-2 col-sm-6 col-xs-12">
                {% bootstrap_field filter_form.date_until layout='inline' %}
            </div>
            <div class="col-md-2 col-sm-6 col-xs-12">
                {% bootstrap_field filter_form.weekday layout='inline' %}
            </div>
            <div class="col-md-2 col-sm-6 col-xs-12">
                <button class="btn btn-primary btn-block" type="submit">
                    <span class="fa fa-filter"></span>
                    <span class="hidden-md">
                    {% trans "Filter" %}
                </span>
                </button>
            </div>
        </form>
        {% if "can_change_event_settings" in request.eventpermset %}
            <p>
                <a href="{% url "control:event.subevents.add" organizer=request.event.organizer.slug event=request.event.slug %}"
                        class="btn btn-default"><i class="fa fa-plus"></i>
                    {% trans "Create a new date" context "subevent" %}</a>
                <a href="{% url "control:event.subevents.bulk" organizer=request.event.organizer.slug event=request.event.slug %}"
                        class="btn btn-default"><i class="fa fa-plus"></i>
                    {% trans "Create many new dates" context "subevent" %}</a>
            </p>
        {% endif %}
        <form action="{% url "control:event.subevents.bulkaction"  organizer=request.event.organizer.slug event=request.event.slug %}" method="post">
            {% csrf_token %}
            <div class="hidden">
                {{ filter_form.as_p }}
            </div>
            <div class="table-responsive">
                <table class="table table-hover table-quotas">
                    <thead>
                    <tr>
                        <th>
                            {% if "can_change_event_settings" in request.eventpermset %}
                                <label aria-label="{% trans "select all rows for batch-operation" %}" class="batch-select-label"><input type="checkbox" data-toggle-table/></label>
                            {% endif %}
                        </th>
                        <th>
                            {% trans "Name" %}
                        </th>
                        <th>
                            {% trans "Begin" %}
                            <a href="?{% url_replace request 'filter-ordering' '-date_from' %}"><i class="fa fa-caret-down"></i></a>
                            <a href="?{% url_replace request 'filter-ordering' 'date_from' %}"><i class="fa fa-caret-up"></i></a>
                        </th>
                        <th>
                            {% trans "Paid tickets per quota" %}
                        </th>
                        <th>
                            {% trans "Status" %}
                            <a href="?{% url_replace request 'filter-ordering' '-active' %}"><i class="fa fa-caret-down"></i></a>
                            <a href="?{% url_replace request 'filter-ordering' 'active' %}"><i class="fa fa-caret-up"></i></a>
                        </th>
                        <th></th>
                    </tr>
                    {% if "can_change_event_settings" in request.eventpermset and page_obj.paginator.num_pages > 1 %}
                        <tr class="table-select-all warning hidden">
                            <td>
                                <input type="checkbox" name="__ALL" id="__all" data-results-total="{{ page_obj.paginator.count }}">
                            </td>
                            <td colspan="5">
                                <label for="__all">
                                    {% trans "Select all results on other pages as well" %}
                                </label>
                            </td>
                        </tr>
                    {% endif %}
                    </thead>
                    <tbody>
                    {% for s in subevents %}
                        <tr>
                            <td>
                                {% if "can_change_event_settings" in request.eventpermset %}
                                    <label aria-label="{% trans "select row for batch-operation" %}" class="batch-select-label"><input type="checkbox" name="subevent" class="batch-select-checkbox" value="{{ s.pk }}"/></label>
                                {% endif %}
                            </td>
                            <td>
                                <strong><a href="{% url "control:event.subevent" organizer=request.event.organizer.slug event=request.event.slug subevent=s.id %}?returnto={{ request.GET.urlencode|urlencode }}">
                                    {{ s.name }}</a></strong>
                            </td>
                            <td>{{ s.get_date_from_display }}</td>
                            <td>
                                {% for q in s.first_quotas|slice:":3" %}
                                    {% include "pretixcontrol/fragment_quota_box_paid.html" with quota=q %}
                                {% endfor %}
                                {% if s.first_quotas|length > 3 %}
                                    <a href="{% url "control:event.products.quotas" organizer=request.event.organizer.slug event=request.event.slug %}?subevent={{ s.id }}"
                                            class="quotabox-more" data-toggle="tooltip" title="{% trans "More quotas" %}"
                                            data-placement="top">
                                        &middot;&middot;&middot;
                                    </a>
                                {% endif %}
                            </td>
                            <td>
                                {% if not s.active %}
                                    <span class="label label-danger">{% trans "Disabled" %}</span>
                                {% elif s.presale_has_ended %}
                                    <span class="label label-warning">{% trans "Presale over" %}</span>
                                {% elif not s.presale_is_running %}
                                    <span class="label label-warning">{% trans "Presale not started" %}</span>
                                {% else %}
                                    <span class="label label-success">{% trans "On sale" %}</span>
                                {% endif %}
                            </td>
                            <td class="text-right flip">
                                <a href="{% url "control:event.subevent" organizer=request.event.organizer.slug event=request.event.slug subevent=s.id %}?returnto={{ request.GET.urlencode|urlencode }}" class="btn btn-default btn-sm"><i class="fa fa-edit"></i></a>
                                <div class="btn-group {% if forloop.revcounter0 < 2 %}dropup{% endif %}">
                                    <button type="button" class="btn btn-default btn-sm dropdown-toggle"
                                            data-toggle="dropdown">
                                        <span class="fa fa-copy"></span>
                                    </button>
                                    <ul class="dropdown-menu dropdown-menu-right">
                                        <li>
                                            <a href="{% url "control:event.subevents.add" organizer=request.event.organizer.slug event=request.event.slug %}?copy_from={{ s.id }}">
                                                {% trans "Use as a template for a new date" context "subevent" %}
                                            </a>
                                        </li>
                                        <li>
                                            <a href="{% url "control:event.subevents.bulk" organizer=request.event.organizer.slug event=request.event.slug %}?copy_from={{ s.id }}">
                                                {% trans "Use as a template for many new dates" context "subevent" %}
                                            </a>
                                        </li>
                                    </ul>
                                </div>
                                <a href="{% url "control:event.subevent.delete" organizer=request.event.organizer.slug event=request.event.slug subevent=s.id %}?returnto={{ request.GET.urlencode|urlencode }}" class="btn btn-delete btn-danger btn-sm"><i class="fa fa-trash"></i></a>
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
            {% if "can_change_event_settings" in request.eventpermset %}
            <div class="batch-select-actions">
                <button type="submit" class="btn btn-delete btn-danger btn-save" name="action" value="delete">
                    <i class="fa fa-trash"></i>{% trans "Delete selected" %}
                </button>
                <button type="submit" class="btn btn-primary btn-save" name="action" value="disable"
                        formaction="{% url "control:event.subevents.bulkedit"  organizer=request.event.organizer.slug event=request.event.slug %}">
                    <i class="fa fa-edit"></i>{% trans "Edit selected" %}
                </button>
                <button type="submit" class="btn btn-default btn-save" name="action" value="enable">
                    <i class="fa fa-check"></i>{% trans "Activate selected" %}
                </button>
                <button type="submit" class="btn btn-default btn-save" name="action" value="disable">
                    <i class="fa fa-ban"></i>{% trans "Deactivate selected" %}
                </button>
            </div>
            {% endif %}
        </form>
        {% include "pretixcontrol/pagination.html" %}
    {% endif %}
{% endblock %}
